package com.bennu.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;


import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    //新增操作自动填充
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info( "公共字段insert" );
        log.info( metaObject.toString() );
        //创建时间
        metaObject.setValue( "createTime", LocalDateTime.now() );
        //更新时间
        metaObject.setValue( "updateTime",LocalDateTime.now() );
        //创建人
        metaObject.setValue( "createUser",BaseContext.getCurrentId() );
        //修改人
        metaObject.setValue( "updateUser",BaseContext.getCurrentId() );

    }
    //修改操作
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info( "updata" );
        log.info( metaObject.toString() );
        //更新时间
        metaObject.setValue( "updateTime",LocalDateTime.now() );
        //修改人
        metaObject.setValue( "updateUser",BaseContext.getCurrentId() );
    }
}
